/**
 * 
 */
package ru.opedge.notifical.util;

import java.util.Iterator;

/**
 * @author opedge
 * 
 */
public class StringLengthIterator implements Iterator<String>
{
	private final int maxLength;

	private final String text;

	private int position = 0;

	public StringLengthIterator(final String text, final int maxLength)
	{
		this.maxLength = maxLength;
		this.text = text;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.util.Iterator#hasNext()
	 */
	@Override
	public boolean hasNext()
	{
		return position < text.length();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.util.Iterator#next()
	 */
	@Override
	public String next()
	{
		int endpos = position + maxLength;

		if (endpos > text.length())
			endpos = text.length();

		final String substr = text.substring(position, endpos);
		position = endpos;
		return substr;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.util.Iterator#remove()
	 */
	@Override
	public void remove()
	{
		throw new RuntimeException("Not implemented method.");
	}

}
